<?php


class My_Auth{
    private $_request;
    private $_auth;
    public $_helperRedirector;

    public static function checkLogin(){
        $auth = Zend_Auth::getInstance();
        $auth->setStorage(new Zend_Auth_Storage_Session(SESSION_NAMESPACE));
        $redirector = new Zend_Controller_Action_Helper_Redirector();
        if(!$auth->hasIdentity()){
            $redirector->gotoUrl('admin/auth/login');exit;
        }
        return $auth->getIdentity();
    }

    public static function logout($sessNamespace = null){
        if(!$sessNamespace){
            $sessNamespace = SESSION_NAMESPACE;
        }
        $auth = Zend_Auth::getInstance()->setStorage(new Zend_Auth_Storage_Session($sessNamespace));
        if($auth->hasIdentity()){
            $auth->clearIdentity();
            return true;
        }
        return false;
    }

}